package com.tf_cut.admin.util;


import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

public class CacheUtil {

    final static Cache<String,String> cache= CacheBuilder.newBuilder()
            .initialCapacity(1000)
            .concurrencyLevel(5)
            .expireAfterWrite(60*60*24, TimeUnit.SECONDS)
            .build();

    public  static String get(String key){
        return cache.getIfPresent(key);
    }

    public  static void put(String key,String value){
         cache.put(key, value);
    }

    public  static void delete(String key){
        try {
            cache.invalidate(key);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
